// pages/contract/contract_main.js
const app = getApp();
const request = require('../../utils/requestAjax.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    StatusBar: app.globalData.StatusBar,
    CustomBar: app.globalData.CustomBar,
    checked:true,
    depType: '',
    depName: '',
    certificateYearList: [],
    depList: [],
    userInfo:{userName:'ww',roleId:1}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    request.requestAjax('/getBaseData', null, '正在加载',
      //请求成功回调
      function (res) {
        wx.setStorageSync('baseData', res.data)
      },
      function (res) {
        wx.hideLoading()
        wx.showModal({
          title: '系统提示',
          content: '获取基础数据失败，请稍后再试',
          showCancel: false,
          success(res) {
            if (res.confirm) {} else if (res.cancel) {}
          }
        })
      })
    this.setData({ 
     // userInfo: wx.getStorageSync('userInfo'),
     depList: wx.getStorageSync('baseData')['1']
    })
    this.setData({  
      title: options.title 
    }) 
    if (options && options.dep_type) {
      this.setData({
        depType: options.dep_type
      })
      var depList = wx.getStorageSync('baseData')['3']
      depList.forEach(element => {
        if (element.codeDetail == this.data.depType) {
          this.setData({
            depName: element.codeContent1
          })
        }
      })
    } 

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  onFilter: (e) => {
    wx.navigateTo({
      url: '/pages/contract/contract_filter/contract_filter'
    })
  },
  onFocus: (e) => {
    wx.navigateTo({
      url: '/pages/contract/contract_filter/contract_about',
    })
  },
  onSearch: function (e) {
    console.log('搜索事件');
    console.log(e.detail);
    wx.navigateTo({
      url: '/pages/contract/contract_filter/contract_list?key='+e.detail+'&type= 2'+'&title='+'关键词查询',
    })
  }
})